#include <iostream>
#include <string>

// 类的成员可以是另一个类的对象，这种类称为类的成员是类的成员对象
class Phone
{
public:
    // 类对象作为类成员时，构造函数的调用顺序是：先调用类的成员对象的构造函数，再调用类的构造函数
    Phone(std::string pName)
    {
        m_PName = pName;
        std::cout << "Phone()" << std::endl;
    }
    // 析构函数的调用顺序是：先调用类的析构函数，再调用类的成员对象的析构函数
    ~Phone()
    {
        std::cout << "~Phone()" << std::endl;
    }
    std::string m_PName;
};

class Person
{
public:
    Person(std::string name, std::string pName) : m_Name(name), m_Phone(pName)
    {
        std::cout << "Person()" << std::endl;
    }
    ~Person()
    {
        std::cout << "~Person()" << std::endl;
    }
    std::string m_Name;
    Phone m_Phone;
};

void test01()
{
    Person p("Jack", "iphone");
    std::cout << p.m_Name << " hold "<< p.m_Phone.m_PName << std::endl;
}

int main()
{
    test01();
    return 0;
}